import { ajax } from '../utils/ajax.js'
import '../lib/jquery.js'

async function render(){
    //如果没有获取到id报错
    let id = sessionStorage.getItem('id');
    if(!id){
        return location.href = './list.html';
    }

    //否则请求详情页
    let {data:{code,info}}= await ajax.get(`/goods/item/${id}`);
    if(code == 0){
        alert('获取详情页失败');
        return location.href = './list.html';
    }

    //标题替换
    $('.title').text(info.title);
    //替换地址
    $('.middleimg').attr('src',info.img_big_logo);
    //html()可以处理识别html标签并解析
    $('.desc').html(info.goods_introduce);
    //text()就是纯粹处理文本
    $('.old').text(info.price);
    $('.discount').text(info.current_price / info.price);
    $('.curprice').text(info.current_price);
}

render();